package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.FileType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IFileTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件类型Controller
 * 
 * @author ess
 * @date 2021-10-18
 */
@RestController
@RequestMapping("/system/fileType")
public class FileTypeController extends BaseController
{
    @Autowired
    private IFileTypeService fileTypeService;

    /**
     * 查询文件类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:fileType:list')")
    @GetMapping("/list")
    public TableDataInfo list(FileType fileType)
    {
        startPage();
        List<FileType> list = fileTypeService.selectFileTypeList(fileType);
        return getDataTable(list);
    }

    /**
     * 导出文件类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:fileType:export')")
    @Log(title = "文件类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FileType fileType)
    {
        List<FileType> list = fileTypeService.selectFileTypeList(fileType);
        ExcelUtil<FileType> util = new ExcelUtil<FileType>(FileType.class);
        return util.exportExcel(list, "文件类型数据");
    }

    /**
     * 获取文件类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:fileType:query')")
    @GetMapping(value = "/{fileTypeId}")
    public AjaxResult getInfo(@PathVariable("fileTypeId") String fileTypeId)
    {
        return AjaxResult.success(fileTypeService.selectFileTypeByFileTypeId(fileTypeId));
    }

    /**
     * 新增文件类型
     */
    @PreAuthorize("@ss.hasPermi('system:fileType:add')")
    @Log(title = "文件类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FileType fileType)
    {
        return toAjax(fileTypeService.insertFileType(fileType));
    }

    /**
     * 修改文件类型
     */
    @PreAuthorize("@ss.hasPermi('system:fileType:edit')")
    @Log(title = "文件类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FileType fileType)
    {
        return toAjax(fileTypeService.updateFileType(fileType));
    }

    /**
     * 删除文件类型
     */
    @PreAuthorize("@ss.hasPermi('system:fileType:remove')")
    @Log(title = "文件类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileTypeIds}")
    public AjaxResult remove(@PathVariable String[] fileTypeIds)
    {
        return toAjax(fileTypeService.deleteFileTypeByFileTypeIds(fileTypeIds));
    }
}
